<h1>Liste des tournois</h1>
<table class="tournamentIndex">
    <tr>
        <th class="bddRender">
            Titre
        </th>
        <th class="bddRender">
            Date de début
        </th>
        <th class="bddRender">
            Date de fin
        </th>
        <th class="bddRender">
            Coefficient [0;1]
        </th>
		<% if is_admin? then %>
	        <th class="bddRenderAdmin">
	            &nbsp;
	        </th>
	        <th class="bddRenderAdmin">
	            &nbsp;
	        </th>
	        <th class="bddRenderAdmin">
	            &nbsp;
	        </th>
		<% end %>	
    </tr>
    <% @tournaments.each do |tournament| %>
    <tr>
        <td>
            <%=h tournament.title %>
        </td>
        <td>
            <%=h tournament.start_date.day.to_s + "." + tournament.start_date.month.to_s + "." + tournament.start_date.year.to_s %>
        </td>
        <td>
            <%=h tournament.end_date.day.to_s + "." + tournament.end_date.month.to_s + "." + tournament.end_date.year.to_s %>
        </td>
        <td>
            <%=h tournament.coefficient01 %>
        </td>
		<% if @current_user_tournaments != nil then %>
	        <% if @current_user_tournaments.include?(tournament) then %>
	        <td>
	            <%= link_to 'Désinscription', unjoin_tournament_path(tournament.id), :query => params[:query] %>
	        </td>
	        <% else %>
	        <td>
	            <%= link_to 'Inscription',join_tournament_path(tournament.id), :query => params[:query] %>
	        </td>
        	<% end %>
        <% end %>
        <% if params[:showJoin] and params[:showJoin].to_i == tournament.id then %>
        <td>
            <%= link_to 'Fermer', :controller => "tournaments", :query => params[:query] %>
        </td>
        <% else %>
        <td>
            <%= link_to 'Qui participe ?', :controller => "tournaments", :showJoin => tournament.id, :query => params[:query] %>
        </td>
        <% end %>
        <%if is_admin? %>
        <td>
            <%= link_to 'Editer', edit_tournament_path(tournament) %>
        </td>
        <td>
            <%= link_to 'Supprimer', tournament, :confirm => 'Etes-vous sûr?', :method => :delete %>
        </td>
    	<%end %>
    </tr>
    <% if params[:showJoin] and params[:showJoin].to_i == tournament.id then %>
    <tr>
        <td valign="top">
            <b>Inscriptions : </b>
        </td>
        <td colspan="7">
            <%= render(:partial => tournament.users) || "Pas de participant pour l'instant" %>
        </td>
    </tr>
    <%end %>
    <%end %>
</table>
<br/>
<% if params[:query] == "archives" then %>
<%= link_to "A venir", :controller => "tournaments" %>
<br/>
<% else %>
<%= link_to "Archives", :controller => "tournaments", :query => "archives" %>
<br/>
<% end %>

<%= link_to 'Nouveau tournoi', new_tournament_path if is_admin? %>

